<template>
    <div>
        <h3>房号增加</h3>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房号名称</td>
                    <td>
                        <input type="text" v-model="querinfo.HouseName">
                    </td>
                </tr>

                <tr>
                    <td align="right">门店</td>
                    <td>
                        <select v-model="querinfo.ShopId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.Shoplist">{{ item.ShopName }}</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td align="right">房型</td>
                    <td>
                        <select v-model="querinfo.HouseTypeId">
                            <option value="">请选择</option>
                            <option :value="item.Id" v-for="item in data.Houselist">{{ item.HouseTypeName }}</option>
                        </select>
                    </td>
                </tr>

                <tr>
                    <td align="right">房态</td>
                    <td>
                        <select v-model="querinfo.HouseState">
                            <option value="">请选择</option>
                            <option :value="1">空闲</option>
                            <option :value="2">已入住</option>
                            <option :value="3">已预约</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <Td>
                        <input type="button" value="增加" @click="ok" class="btn btn-primary">
                    </Td>
                </tr>


            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted, useSlots } from 'vue';
import { useRouter, useRoute } from 'vue-router';
import moment from 'moment';
import axios from 'axios';
const route = useRoute();
const router = useRouter();

//存储门店
let data: any = reactive({
    Shoplist: [],
    Houselist: [],
})

let querinfo:any=reactive({
 "HouseName": "",
  "ShopId": "",
  "HouseTypeId": "",
  "HouseState": "",
})


onMounted(() => {
    getList();
    GetHouse();
})



//房号增加
const ok = () => {
    if(querinfo.HouseName==""){
        alert('房间号不能为空');
        return;
    }
    if(querinfo.ShopId==""){
        alert('门店必选');
        return;
    }
    if(querinfo.HouseTypeId==""){
        alert('房型必选');
        return;
    }
    if(querinfo.HouseState==""){
        alert('房态必选');
        return;
    }
    axios({
        method: "post",
        url: "/api/House/HouseNoAdd",
        data:querinfo
    })
    .then(res=>{
        if(res.data>0){
            alert('添加成功')
            router.push('/houseNoList');
        }
        else if(res.data==-1){
            alert('房号名称重复')
        }
        else{
            alert('添加失败')
        }
    })
    .catch(err=>{
        console.log(err);
    })
}

//获取房型
const GetHouse = () => {
    axios({
        method: "get",
        url: "/api/House/GetHouseTypeList",
        params: {
            pageIndex: 1,
            pageSize: 10000
        }
    })
        .then(res => {
            data.Houselist = res.data.list;
        })
        .catch(err => {
            console.log(err);
        })
}



//获取门店列表数据
const getList = () => {
    axios({
        method: "get",
        url: "/api/Shops/GetShopList",
        params: {
            pageIndex: 1,
            pageSize: 10000
        }
    })
        .then(res => {
            console.log(res);
            data.Shoplist = res.data.list;
        })
        .catch(err => {
            console.log(err)
        })
}

</script>






<style scoped></style>